const path = require("path");
const LessPluginAutoPrefix = require("less-plugin-autoprefix");
var prod = process.env.NODE_ENV === "production";
/**
 *  wepy 的配置文件
 * @type {{wpyExt: string, eslint: boolean, cliLogs: boolean, build: {}, resolve: {alias: {@: string}, modules: [string]}, compilers: {less: {compress: boolean}, babel: {sourceMap: boolean, presets: [string], plugins: [string,string,string,string]}}, plugins: {}, appConfig: {noPromiseAPI: [string]}}}
 */
module.exports = {
    wpyExt: ".vue",  // 文件统一后缀为 vue
    eslint: false,
    cliLogs: !prod,
    build: {},
    resolve: {
        alias: {
            "@": path.join(__dirname, "src")
        },
        modules: ["node_modules"]
    },
    compilers: {
        less: {
            compress: prod,
            plugins: [new LessPluginAutoPrefix({browsers: ["Android >= 2.3", "Chrome > 20", "iOS >= 6"]})]

        },
        /*sass: {
          outputStyle: "compressed"
        },*/
        /*
          wepy项目中使用async await
         */
        babel: {
            sourceMap: false,
            presets: [
                "env"
            ],
            plugins: [
                "transform-class-properties",
                "transform-decorators-legacy",
                "transform-object-rest-spread",
                "transform-export-extensions",
                "syntax-export-extensions"
            ]
        }
    },
    plugins: {}
}

if (prod) {

    // 压缩sass
    // module.exports.compilers["sass"] = {outputStyle: "compressed"}

    // 压缩js
    module.exports.plugins = {
        "uglifyjs": {
            filter: /\.js$/,
            config: {}
        },
        imagemin: {
            filter: /\.(jpg|png|jpeg)$/,
            config: {
                jpg: {
                    quality: 80
                },
                png: {
                    quality: 80
                }
            }
        }
    }
}
